package com.jinke.uang.model;

import android.location.Location;

import com.jinke.uang.BuildConfig;
import com.jinke.uang.AppApplication;
import com.jinke.uang.common.UserInfo;
import com.jinke.uang.constant.HttpConstant;
import com.jinke.uang.http.ModelUtils;
import com.jinke.uang.http.ParamsFactory;
import com.jinke.uang.http.RetrofitManager;
import com.jinke.uang.interfaces.ICommonModule;
import com.jinke.uang.interfaces.ICommonView;
import com.jinke.uang.utils.LocationUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者：Song Shuyu
 * 时间：2019/4/11 10:42
 * package is com.jinke.uang.model
 * 登录相关的网络请求数据
 */
public class LoginModule implements ICommonModule {

    @Override
    public void getData(ICommonView view, int apiType,String listType, Object[] t) {
        Map<String, Object> params = new HashMap<>();
        switch (apiType) {

            case HttpConstant.OLD_LOGIN_DATA://老用户登录页面
                params.put("userName", String.valueOf(t[0]));
                params.put("passWord", String.valueOf(t[1]));
                ModelUtils.ModelUtils(RetrofitManager.getInstance().getINetService().login
                        (ParamsFactory.getCommonParams(params)), view, apiType, listType,t);
                break;

            case HttpConstant.FACEBOOK_LOGIN://facebook登录界面
                params.clear();
                params.put("authCode", String.valueOf(t[0]));
                ModelUtils.ModelUtils(RetrofitManager.getInstance().getINetService().faceBookLogin
                        (BuildConfig.channel, ParamsFactory.getCommonParams(params)), view, apiType,listType, t);
                break;

            case HttpConstant.REGISTER_QUEST://注册接口
                params.clear();
                params.put("userName", String.valueOf(t[0]));
                params.put("passWord", String.valueOf(t[1]));
                params.put("checkCode", String.valueOf(t[2]));
                params.put("type", String.valueOf(t[3]));
                ModelUtils.ModelUtils(RetrofitManager.getInstance().getINetService().doRegisterQuest
                        (ParamsFactory.getCommonParams(params)), view, apiType, listType,t);
                break;

            case HttpConstant.UPLOAD_LOCATION_REGISTER://获取经纬度的注册接口
                Location location = LocationUtils.getLocation(AppApplication.getContext());
                params.clear();
                params.put("longitude", String.valueOf(location.getLongitude()));
                params.put("latitude", String.valueOf(location.getLatitude()));
                params.put("saveType", "1");
                params.put("userPhone", String.valueOf(t[0]));
                ModelUtils.ModelUtils(RetrofitManager.getInstance().getINetService().uploadLocationRegister
                        (BuildConfig.channel, UserInfo.getToken(), ParamsFactory
                                .getCommonParams(params)), view, apiType,listType, t);
                break;

            case HttpConstant.VOICE_CODE://语音验证注册接口
                params.clear();
                params.put("userName", String.valueOf(t[0]));
                ModelUtils.ModelUtils(RetrofitManager.getInstance().getINetService().getVoiceCode
                        (BuildConfig.channel, ParamsFactory.getCommonParams(params)), view, apiType,listType, t);
                break;

            case HttpConstant.SMS_CODE://短信验证注册接口
                params.clear();
                params.put("userName", String.valueOf(t[0]));
                ModelUtils.ModelUtils(RetrofitManager.getInstance().getINetService().getVerifyCode
                        (BuildConfig.channel, ParamsFactory.getCommonParams(params)), view, apiType,listType, t);
                break;

            default:
                break;
        }
    }
}
